package net.csdra.libraryborrowing.service.book;

import net.csdra.libraryborrowing.domain.book.BookOrder;

import javax.transaction.Transactional;
import java.nio.file.AccessDeniedException;
import java.util.List;

/**
 * Created by msf on 2017/10/16.
 */
public interface BookOrderService {

    /**
     * 用户发起借阅。
     * 新建一个BookOrder状态为WAITACCEPT
     * 根据bookInfoIds生成BookOrderMaterial
     * 对应BookCope的state必须为在馆
     * 设置consigneeUserId赋值为当用用户Id
     * 设置consigneeShippingAddressId为用户选择的收货地址Id     *
     * 创建一个BookOrderLog对象
     *
     * @param createBookOrder
     * @return
     */
    @Transactional
    public BookOrder createBookOrder(CreateBookOrder createBookOrder) throws AccessDeniedException;


    /**
     * 确认到货
     * 订单收货用户必须为当前用户
     * 将订单状态修改为COMPLETED，订单当前状态必须为DISTRIBUTION
     * 将订单对象所有副本状态修改为外借
     * 创建BookOrderLog
     *
     * @param acceptBookOrder
     * @return
     */
    public BookOrder acceptBookOrder(AcceptBookOrder acceptBookOrder);

    /**
     * 确认到货（异常收货）
     * 订单收货用户必须为当前用户
     * 将订单状态修改为USERREJECTS，订单当前状态必须为DISTRIBUTION
     * 将订单对象所有副本状态修改为快递中
     * 创建BookOrderLog
     *
     * @param rejectBookOrder
     * @return
     */
    public BookOrder rejectBookOrder(RejectBookOrder rejectBookOrder);


    /**
     * 当前用户发起还书请求
     * 1，判断所有副本状态是否正确（必须为当前用户借阅的副本）
     * 2，创建订单发货人为当前用户，收货人为图书馆默认user
     *
     * @param handleRemandBookCopy
     * @return
     */
    public BookOrder remandBookCopy(RemandBookCopy handleRemandBookCopy);

    class CreateBookOrderMaterial {
        String bookInfoId;
        int number;

        public String getBookInfoId() {
            return bookInfoId;
        }

        public void setBookInfoId(String bookInfoId) {
            this.bookInfoId = bookInfoId;
        }

        public int getNumber() {
            return number;
        }

        public void setNumber(int number) {
            this.number = number;
        }
    }

    class CreateBookOrder {
        //订单书籍副本列表
        List<CreateBookOrderMaterial> createBookOrderMaterials;
        //收货人地址信息
        String consigneeShippingAddressId;
        String remark;

        public List<CreateBookOrderMaterial> getCreateBookOrderMaterials() {
            return createBookOrderMaterials;
        }

        public void setCreateBookOrderMaterials(List<CreateBookOrderMaterial> createBookOrderMaterials) {
            this.createBookOrderMaterials = createBookOrderMaterials;
        }

        public String getConsigneeShippingAddressId() {
            return consigneeShippingAddressId;
        }

        public void setConsigneeShippingAddressId(String consigneeShippingAddressId) {
            this.consigneeShippingAddressId = consigneeShippingAddressId;
        }

        public String getRemark() {
            return remark;
        }

        public void setRemark(String remark) {
            this.remark = remark;
        }
    }

    class AcceptBookOrder {
        String bookOrderId;
        String remark;
    }

    class RejectBookOrder extends AcceptBookOrder {
    }

    class RemandBookCopy {
        List<String> bookCopys;

        public List<String> getBookCopys() {
            return bookCopys;
        }

        public void setBookCopys(List<String> bookCopys) {
            this.bookCopys = bookCopys;
        }
    }
}
